package cn.crystalorigin.plugin

import cn.crystalorigin.plugin.util.Nameable
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.logging.LogManager
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KClass
import kotlin.reflect.KProperty

@Suppress("RedundantSuspendModifier")
abstract class AsyncLoader : Nameable , ReadOnlyProperty<AsyncLoader, Logger> {
    open suspend fun load() {}

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        return other is AsyncLoader && this.name == other.name
    }

    override fun hashCode(): Int {
        return javaClass.hashCode()
    }

    override fun getValue(thisRef: AsyncLoader, property: KProperty<*>): Logger {
        return LoggerFactory.getLogger(nameAsString)
    }
}

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class MustAfter(val prev: KClass<out AsyncLoader>)